<?php
class NewsDao {
	private $table = 'news';
	public function count(){
		$count = ClassManager::getSql()->onedata($this->table,"count(*)  ");
		return  $count[0];
	}
	public function getList($limit){
		return  ClassManager::getSql()->datalist($this->table,'*'," order by id desc ",$limit);
	}
	public function get($id){
		return  ClassManager::getSql()->onedata($this->table,'*',"where id='".intval($id)."'");
	}
	public function add($data){
		ClassManager::getSql()->insert($this->table, $data);
	}
	public function update($data,$id){
		ClassManager::getSql()->updates($this->table, $data,"where id=".intval($id));
	}
	public function deleteBatchByid($id){
		ClassManager::getSql()->delete($this->table,"where id in(".$id.")");
	}
	
	public function getNewIdByNavidList($nav_id_list_str){
		return ClassManager::getSql()->dataList1($this->table,'id,nav_id'," where nav_id in (".$nav_id_list_str.")");
	}
	
	public function getNewIdWithNavId(){
		return ClassManager::getSql()->dataList1($this->table,'id,nav_id'," where nav_id !=0 ");
	}
	
	
	public function getNewInfoByNavId($nav_id){
		return ClassManager::getSql()->onedata($this->table,'*'," where nav_id='".$nav_id."' ");
	}
	
	public function searchList($where=array(),$order='',$limit=0){
		$where = $this->searchWhere($where);
		return ClassManager::getSql()->dataList1($this->table,'*',$where,$order,$limit);
	}
	public function searchNumber($where= array()){
		$where = $this->searchWhere($where);
		$tmp = ClassManager::getSql()->onedata1($this->table,"count(*)  ",$where);
		return $tmp[0];
	}
	public function searchWhere($where){
		$where1 = array();
		$likeWhere = array('title');
		foreach ($where as  $k=>$v){
			if (isset($v)&&$v!==""){
				if (in_array($k,$likeWhere) and !is_array($v)){
					$where1[$k] = array('%'.$v.'%' , 'like');
				}
				else{
					$where1[$k] =  $v;
				}
			}	
		}
		unset($where);
		return $where1;
	}
}
?>